import 'package:mobpush_plugin/mobpush_plugin.dart';
import 'package:mobpush_plugin/mobpush_local_notification.dart';
import 'dart:io';

class MobPush{

    MobPush(){
        init();
        getRegID();
    }

    init(){
        MobpushPlugin.addPushReceiver(_onEvent, _onError);
    }

    void _onEvent(Object event) {
        print('>>>>>>>>>>>>>>>>>>>>>>>>>>>onEvent:' + event.toString());
    }

    void _onError(Object event) {
        print('>>>>>>>>>>>>>>>>>>>>>>>>>>>onError:' + event.toString());
    }

    void getRegID(){
        MobpushPlugin.getRegistrationId().then((Map<String, dynamic> ridMap) {
            print(ridMap);
            String regId = ridMap['res'].toString();
            print('------>#### registrationId: ' + regId);
        });
    }

    static void  sendLocalNotification(String info)  async {
        if (Platform.isIOS) {    // iOS

            MobPushLocalNotification localNotification = new MobPushLocalNotification(
                title: "正标题",//本地通知标题
                content: info, //本地通知内容
                timestamp: 0, //本地通知时间戳, 0立刻通知。其余为时间间隔
                badge: 1, //  ios角标
                sound: "default", // ios声音
                subTitle: "副标题",
                extrasMap: {"extra":"testExtra"} // ios副标题
            );// ios副标题
            await MobpushPlugin.addLocalNotification(localNotification);

        } else { // Android
            MobPushLocalNotification localNotification = new MobPushLocalNotification(
                notificationId: 0,//notificationId
                title: "本地通知",//本地通知标题
                content:info,//本地通知内容
                messageId: null,//消息id
                inboxStyleContent: null,//收件箱样式的内容
                timestamp: new DateTime.now().millisecondsSinceEpoch,//本地通知时间戳
                style: 0,//通知样式
                channel: 0,//消息通道
                extrasMap: null,//附加数据
                voice: true,//声音
                shake: true,//真的
                styleContent: null,//大段文本和大图模式的样式内容
                light: true,//呼吸灯
            );
            await MobpushPlugin.addLocalNotification(localNotification);
        }
    }

}

// 插件使用说明：http://www.mob.com/wiki/detailed?wiki=MobPushForFlutterfenlei&id=136

//1.注册使用方法
//开始函数的initState中注册 MobPush();


